package com.zhan.cloud.hello;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

import lombok.Data;

@Data
@Configuration
@ConfigurationProperties(prefix="spring.rabbitmq")
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
	
	private String host;
	
	private int port;
	
	private String username;
	
	private String password;
	
	
    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        //config.enableSimpleBroker("/topic");
    	config.enableStompBrokerRelay("/topic")
    			.setVirtualHost("/")
    			.setRelayHost(this.host)
    			.setRelayPort(this.port)
    			.setClientLogin(this.username)
    			.setClientPasscode(this.password);
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/gs-guide-websocket").withSockJS();
    }

}